home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11039 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  50 lines

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: symbol type at runtime
  5. Date: 21 Mar 1996 15:50:12 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4irtrk$2vn@sparcserver.lrz-muenchen.de>
  9. References: <Pine.OSF.3.91.960320170224.19850A-100000@krtkg1.rug.ac.be>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Christophe Colle <colle@krtkg1.rug.ac.be> writes:
  13.  
  14. >Hi all,
  15.  
  16. >I wonder if there is a way to find out the type of a variable at runtime, 
  17. >without using tricks like #define etc.
  18.  
  19. >eg:
  20.  
  21. >char array[10];
  22.  
  23. >int function(int blah, char *ptr)
  24. >{
  25. >  /* in this function i want to find the exact type of the variabl which 
  26. >     is passed in ptr. I want to find a char  array[10] and not char * 
  27. >     when called with    function(blah, array);
  28. >  /*
  29.  
  30. Since the type of "ptr" _is_ pointer to char and _not_ array of 10 chars,
  31. you _don't_ want to find the type of "ptr", you want to find something
  32. different. Consider the following call to function:
  33.  
  34.    char *p = malloc(n);
  35.    if (p) {
  36.       /* Initialize p */
  37.       function(bleh, p);
  38.    }
  39.  
  40. What should your "type detection" do in this situation? If you want
  41. to know the length of a vector passed to a C function, you have to
  42. pass that length to the function.
  43.  
  44. Kurt
  45. -- 
  46. | Kurt Watzka                             Phone : +49-89-2180-6254
  47. | watzka@stat.uni-muenchen.de
  48. | ua302aa@sunmail.lrz-muenchen.de
  49.  
  50.